﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFSamplesStudy._3D
{
  /// <summary>
  /// HandRotateCube.xaml 的交互逻辑
  /// </summary>
  public partial class HandRotateCube : Page
  {
    public HandRotateCube()
    {
      InitializeComponent();
    }

    // 后台代码
    private Point lastMousePos;
 
    private void Viewbox_MouseWheel(object sender, MouseWheelEventArgs e)
    {
      myPerspectiveCamera.Position = new System.Windows.Media.Media3D.Point3D(myPerspectiveCamera.Position.X, myPerspectiveCamera.Position.Y, myPerspectiveCamera.Position.Z - e.Delta / 500d);
    }

    private void MainBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      if (e.LeftButton == MouseButtonState.Pressed)
      {
        lastMousePos = e.GetPosition(MainBorder);

      }
    }

    private void MainBorder_MouseMove(object sender, MouseEventArgs e)
    {
      if (e.LeftButton == MouseButtonState.Pressed)
      {
        var now = e.GetPosition(MainBorder);

        var X1 = now.X - lastMousePos.X;
        myHorizontalRotation.Angle -= X1 / 2;

        var y1 = now.Y - lastMousePos.Y;
        myVerticalRotation.Angle -= y1 / 2;
        //Debug.WriteLine($"X1:{X1},Y1:{y1} H-Angle:{myHorizontalRotation.Angle} V-Angle:{myVerticalRotation.Angle}");
        lastMousePos = now;
      }
    }
  }
}
